package org.will.aop.t1;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.will.aop.TransactionManager;
import org.will.aop.UserService;

@Slf4j
@Service("userServiceImpl")
public class UserServiceImpl implements UserService {

    @Autowired
    private TransactionManager txManager;

    @Override
    public void save() {
        try{
            txManager.begin();
            log.info("保存用户");
            txManager.commit();
        }catch (Exception e){
            txManager.rollback();
            log.error("保存用户发生异常", e);
        }
    }

    @Override
    public void update() {
        try{
            txManager.begin();
            log.info("更新用户");
            txManager.commit();
        }catch (Exception e){
            txManager.rollback();
            log.error("保存用户发生异常", e);
        }
    }
}
